﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Adex;
using Telerik.Web.UI;
using MediaMonitor.Common;

namespace MediaMonitor.Users
{
    public partial class SearchVideo : System.Web.UI.Page
    { DateTime sDate = DateTime.MinValue, eDate = DateTime.MinValue;
        protected void Page_Load(object sender, EventArgs e)
        {
            SetCalendarDates();  
        }
        private void SetCalendarDates()
        {


            DataTable dt = TblNewsAlert.Query().DISTINCT().SetSelectList("RFDate").ExecuteDataSet().Tables[0];


            foreach (DataRow dr in dt.Rows)
            {

                RadCalendarDay d1 = new RadCalendarDay(calS);
                d1.Date = Utility.ToDateTime(dr["RFDate"]);
                d1.IsDisabled = false;
                d1.IsSelectable = true;

                d1.ItemStyle.BackColor = System.Drawing.Color.PowderBlue;
                d1.ItemStyle.ForeColor = System.Drawing.Color.White;

                calS.SpecialDays.Add(d1);

                RadCalendarDay d2 = new RadCalendarDay(calE);
                d2.Date = Utility.ToDateTime(dr["RFDate"]);
                d2.IsDisabled = false;
                d2.IsSelectable = true;

                d2.ItemStyle.BackColor = System.Drawing.Color.PowderBlue;
                d2.ItemStyle.ForeColor = System.Drawing.Color.White;


                calE.SpecialDays.Add(d2);
            }



        }
        protected void btnSearch_Click(object sender, EventArgs e)
        {
             bool tmp1 = DateTime.TryParse(calS.SelectedDate.ToShortDateString(), out sDate);
            bool tmp2 = DateTime.TryParse(calE.SelectedDate.ToShortDateString(), out eDate);

            if (sDate < Utility.ToDateTime("01/01/2000"))         //Calendar Start Date
                sDate = Utility.ToDateTime("");

            if (eDate < Utility.ToDateTime("01/01/2000"))        //Calendar End Date
                eDate = Utility.ToDateTime("01/01/2000");

            //mediaTypeCode = Utility.ToInt(lstNewsMediaType.SelectedValue);


           

            DataTable dt=SPs.GetReportVideoNewsAlert(sDate.ToString(),eDate.ToString(),txtNewsTitle.Text.ToString()).GetDataSet().Tables[0];
            if (dt.Rows.Count > 0)
            {
                radGrid.DataSource = dt;
                radGrid.DataBind();
                pnlSearch.Visible = false;
            }
        }
    }
}